package com.zxl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxl.entity.Goods;
import com.zxl.entity.Stock;
import com.zxl.mapper.GoodsMapper;
import com.zxl.mapper.StockMapper;
import com.zxl.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @packageName com.zxl.service.impl
 * @ClassName
 * @Author zxl
 * @Description //TODO
 * @date
 **/
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private StockMapper stockMapper;

    @Override
    @Transactional
    public Goods saveGoodsAndStock(Goods goods) {
        try {
            goodsMapper.insert(goods);
            Stock stock = new Stock();
            stock.setCount(goods.getCount());
            stock.setGid(goods.getId());
            stockMapper.insert(stock);
            return goods;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
